using System;
using System.Collections.Generic;
using System.Text;

namespace PSE.Hosting.Management.Console
{
    class HelpCommand : ICommand
    {
        #region ICommand Members

        public void Execute(string[] args)
        {
            if (args.Length > 1)
            {
                Messages.InvalidHelpCommand();
                return;
            }

            this.WriteHelpMessage();
        }

        #endregion

        private void WriteHelpMessage()
        {
            StringBuilder helpMessage = new StringBuilder();
            helpMessage.Append(Messages.WriteHeader());

            helpMessage.AppendLine("USAGE:");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   HosterConsole.exe <command> [ <options> ]");
            helpMessage.AppendLine();
            helpMessage.AppendLine("COMMANDS:");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   /createPackage    - Creates a package. (Short Form: /cp) ");
            helpMessage.AppendLine("   /removePackage    - Removes a package. (Short Form: /rp) ");
            helpMessage.AppendLine("   /startPackage     - Starts all WCF services of all assemblies containing in a package. (Short Form: /stp) ");
            helpMessage.AppendLine("   /stopPackage      - Stops all WCF services of all assemblies containing in a package. (Short Form: /spp) ");
            helpMessage.AppendLine("   /add              - Adds an assembly to be hosted by BM&FBOVESPA Service Hoster. (Short Form: /a)");
            helpMessage.AppendLine("   /remove           - Removes an assembly hosted by BM&FBOVESPA Service Hoster. (Short Form: /r)");
            helpMessage.AppendLine("   /start            - Starts WCF Services of an assembly hosted by BM&FBOVESPA Service Hoster. (Short Form: /st)");
            helpMessage.AppendLine("   /stop             - Stops WCF Services of an assembly hosted by BM&FBOVESPA Service Hoster. (Short Form: /sp)");
            helpMessage.AppendLine("   /help             - Displays command syntax and options for the tool. (Short Form: /?)");
            helpMessage.AppendLine();
            helpMessage.AppendLine();
            helpMessage.AppendLine("GENERAL OPTIONS:");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   /silent           - Using this option in any command above, the results and exceptions are not shown in console.");
            helpMessage.AppendLine();
            helpMessage.AppendLine();
            helpMessage.AppendLine("==============================================================");
            helpMessage.AppendLine("-=                      CREATE PACKAGE                      =-");
            helpMessage.AppendLine("==============================================================");
            helpMessage.AppendLine();
            helpMessage.AppendLine("Description: ");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   Creates a package. (Short Form: /cp) ");
            helpMessage.AppendLine();
            helpMessage.AppendLine("Syntax: ");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   HosterConsole.exe /createPackage <packageName>");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   <packageName> - The name of the package to be created.");
            helpMessage.AppendLine();
            helpMessage.AppendLine("Examples:");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   HosterConsole.exe /createPackage bovespa");
            helpMessage.AppendLine("   - Creates a package named BOVESPA.");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   HosterConsole.exe /cp bovespa");
            helpMessage.AppendLine("   - Same as above but in the short form.");
            helpMessage.AppendLine();
            helpMessage.AppendLine();
            helpMessage.AppendLine("==============================================================");
            helpMessage.AppendLine("-=                      REMOVE PACKAGE                      =-");
            helpMessage.AppendLine("==============================================================");
            helpMessage.AppendLine();
            helpMessage.AppendLine("Description: ");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   Removes a package. (Short Form: /rp) ");
            helpMessage.AppendLine();
            helpMessage.AppendLine("Syntax: ");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   HosterConsole.exe /removePackage <packageName>");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   <packageName> - The name of the package to be removed.");
            helpMessage.AppendLine();
            helpMessage.AppendLine("Examples:");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   HosterConsole.exe /removePackage bovespa");
            helpMessage.AppendLine("   - Removes the package named BOVESPA.");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   HosterConsole.exe /rp bovespa");
            helpMessage.AppendLine("   - Same as above but in the short form.");
            helpMessage.AppendLine();
            helpMessage.AppendLine();
            helpMessage.AppendLine("==============================================================");
            helpMessage.AppendLine("-=                      START PACKAGE                       =-");
            helpMessage.AppendLine("==============================================================");
            helpMessage.AppendLine();
            helpMessage.AppendLine("Description: ");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   Starts all WCF services of all assemblies containing in a package. (Short Form: /stp) ");
            helpMessage.AppendLine("   This command runs in background. Check the WCF Hoster Manager if the services started sucessfully.");
            helpMessage.AppendLine();
            helpMessage.AppendLine("Syntax: ");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   HosterConsole.exe /startPackage [/synchronous:<synchronous>] <packageName>");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   <synchronous> - (Optional) Set this option to true if the package must be started in a synchronous fashion. If suppressed it defaults to false.");
            helpMessage.AppendLine("   <packageName> - The name of the package containing the assemblies to start.");
            helpMessage.AppendLine();
            helpMessage.AppendLine("Examples:");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   HosterConsole.exe /startPackage BOVESPA");
            helpMessage.AppendLine("   - Starts all WCF services contained in all assemblies of package BOVESPA.");
            helpMessage.AppendLine();
            helpMessage.AppendLine();
            helpMessage.AppendLine("==============================================================");
            helpMessage.AppendLine("-=                       STOP PACKAGE                       =-");
            helpMessage.AppendLine("==============================================================");
            helpMessage.AppendLine();
            helpMessage.AppendLine("Description: ");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   Stops all WCF services of all assemblies containing in a package. (Short Form: /spp) ");
            helpMessage.AppendLine();
            helpMessage.AppendLine("Syntax: ");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   HosterConsole.exe /stopPackage [/synchronous:<synchronous>] <packageName>");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   <synchronous> - (Optional) Set this option to true if the package must be stopped in a synchronous fashion. If suppressed it defaults to false.");
            helpMessage.AppendLine("   <packageName> - The name of the package containing the assemblies to stop.");
            helpMessage.AppendLine();
            helpMessage.AppendLine("Examples:");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   HosterConsole.exe /stopPackage BOVESPA");
            helpMessage.AppendLine("   - Stops all WCF services contained in all assemblies of package BOVESPA.");
            helpMessage.AppendLine();
            helpMessage.AppendLine();
            helpMessage.AppendLine("==============================================================");
            helpMessage.AppendLine("-=                       ADD ASSEMBLY                       =-");
            helpMessage.AppendLine("==============================================================");
            helpMessage.AppendLine();
            helpMessage.AppendLine("Description: ");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   Adds an assembly to be hosted by BM&FBOVESPA Service Hoster. (Short Form: /a)");
            helpMessage.AppendLine();
            helpMessage.AppendLine("Syntax: ");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   HosterConsole.exe /add /package:<packageName> [/domain:<domain>] [/username:<userName>] [/password:<password>] <assembly>");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   <packageName> - The name of the package where the assembly will be added.");
            helpMessage.AppendLine("   <domain>      - (Optional) Domain that the user is registered. Used only in case that the assembly need to be loaded with higher privileges.");
            helpMessage.AppendLine("   <userName>    - (Optional) The user name for impersonation. Used only in case that the assembly need to be loaded with higher privileges.");
            helpMessage.AppendLine("   <password>    - (Optional) The password of the user for impersonation. Used only in case that the assembly need to be loaded with higher privileges.");
            helpMessage.AppendLine("   <assembly>    - The file to be added.");
            helpMessage.AppendLine();
            helpMessage.AppendLine("Examples:");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   HosterConsole.exe /add /package:PSE C:\\Assemblies\\PSE.ServiceImplementation.dll");
            helpMessage.AppendLine("   - Adds PSE.ServiceImplementation.dll assembly to PSE package.");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   HosterConsole.exe /a /package:PSE C:\\Assemblies\\PSE.ServiceImplementation.dll");
            helpMessage.AppendLine("   - Same as above but in the short form.");
            helpMessage.AppendLine();
            helpMessage.AppendLine();
            helpMessage.AppendLine("==============================================================");
            helpMessage.AppendLine("-=                     REMOVE ASSEMBLY                       =-");
            helpMessage.AppendLine("==============================================================");
            helpMessage.AppendLine();
            helpMessage.AppendLine("Description: ");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   Removes an assembly hosted by BM&FBOVESPA Service Hoster. (Short Form: /r)");
            helpMessage.AppendLine();
            helpMessage.AppendLine("Syntax: ");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   HosterConsole.exe /remove /package:<packageName> <fileName>");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   <packageName> - The name of the package where the assembly is located.");
            helpMessage.AppendLine("   <fileName>    - The name of the file to be started. This should be the file name only, without the full path.");
            helpMessage.AppendLine();
            helpMessage.AppendLine("Examples:");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   HosterConsole.exe /remove /package:PSE PSE.ServiceImplementation.dll");
            helpMessage.AppendLine("   - Removes PSE.ServiceImplementation.dll assembly from PSE package.");
            helpMessage.AppendLine();
            helpMessage.AppendLine();
            helpMessage.AppendLine("==============================================================");
            helpMessage.AppendLine("-=                      START ASSEMBLY                      =-");
            helpMessage.AppendLine("==============================================================");
            helpMessage.AppendLine();
            helpMessage.AppendLine("Description: ");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   Starts WCF Services of an assembly hosted by BM&FBOVESPA Service Hoster. (Short Form: /st)");
            helpMessage.AppendLine();
            helpMessage.AppendLine("Syntax: HosterConsole.exe /start /package:<packageName> <fileName>");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   <packageName> - The name of the package where the assembly is located.");
            helpMessage.AppendLine("   <fileName>    - The name of the file to be started. This should be the file name only, without the full path.");
            helpMessage.AppendLine();
            helpMessage.AppendLine("Examples:");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   HosterConsole.exe /start /package:PSE PSE.ServiceImplementation.dll");
            helpMessage.AppendLine("   - Starts all WCF services contained in PSE.ServiceImplementation.dll assembly.");
            helpMessage.AppendLine();
            helpMessage.AppendLine();
            helpMessage.AppendLine("==============================================================");
            helpMessage.AppendLine("-=                       STOP ASSEMBLY                      =-");
            helpMessage.AppendLine("==============================================================");
            helpMessage.AppendLine();
            helpMessage.AppendLine("Description: ");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   Stops WCF Services of an assembly hosted by BM&FBOVESPA Service Hoster. (Short Form: /sp)");
            helpMessage.AppendLine();
            helpMessage.AppendLine("Syntax: HosterConsole.exe /stop /package:<packageName> <fileName>");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   <packageName> - The name of the package where the assembly is located.");
            helpMessage.AppendLine("   <fileName>    - The name of the file to be stopped. This should be the file name only, without the full path.");
            helpMessage.AppendLine();
            helpMessage.AppendLine("Examples:");
            helpMessage.AppendLine();
            helpMessage.AppendLine("   HosterConsole.exe /stop /package:PSE PSE.ServiceImplementation.dll");
            helpMessage.AppendLine("   - Stops all WCF services contained in PSE.ServiceImplementation.dll assembly.");
            helpMessage.AppendLine();
            helpMessage.AppendLine();

            System.Console.Write(helpMessage.ToString());
        }
    }
}
